package com.GUI.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Text {
    public static void main(String[] args) {
        //只放启动
        MyFrame myFrame =  new MyFrame();
    }
}
class MyFrame extends Frame{
    public MyFrame(){
        //声明文本框
        TextField textField = new TextField();
        //添加文本框到MyFrame
        add(textField);
        // 声明监听

        MyActionlistener2 myActionlistener2 = new MyActionlistener2();
        textField.addActionListener(myActionlistener2);

        //设置替换编码123-》***
        textField.setEchoChar('*');
        //设置可见性
        setVisible(true);
        //文本框大小自适应
        pack();
    }
}
//监听
class MyActionlistener2 implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        //获得一些资源
        TextField field = (TextField) e.getSource();
        //获得输入框中的文本
        System.out.println(field.getText());

        //按下enter后发送并删除文本框内容
        field.setText("");
    }
}
